package org.xtown.bingluo.xtieba.db;

import org.xtown.bingluo.xtieba.db.DBInfo.DB;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 数据库操作帮助类
 * 
 */
public class DBHelper extends SQLiteOpenHelper {

	public DBHelper(Context context) {

		super(context, DBInfo.DB.DB_NAME, null, DB.VERSION);
	}

	public void onCreate(SQLiteDatabase db) {
		try {
			db.execSQL(DBInfo.Table.POSTS_CREATE);
			db.execSQL(DBInfo.Table.POSTS_INFO_CREATE);
			db.execSQL(DBInfo.Table.AUTHOR_CREATE);
		} catch (SQLException ex) {  
	    	db.close();
	    }
	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		try {
			db.execSQL(DBInfo.Table.POSTS_DROP);
			db.execSQL(DBInfo.Table.POSTS_INFO_DROP);
			db.execSQL(DBInfo.Table.AUTHOR_DROP);
			onCreate(db);
		} catch (SQLException ex) {  
	    	db.close();
	    }

	}

}
